<?=$this->header(true, true)?>


    <?=$this->menu("newsletters")?>


    <h1><?=$this->message("nav.newsletters")?></h1>


    <? /* Breadcrums route */ ?>
    <?=$this->route(
        array(
            array(
                "name"=>$this->message("nav.newsletters"),
                "href"=>"newsletter/list"
            ),
            array(
                "name"=>$this->message("route.edit", _Core::BUNDLE) . " " . $this->message("label.recipients", _Newsletter::BUNDLE) . " " .
                    $this->message("label.newsletter", _Newsletter::BUNDLE). " \"".$this->newsletter($this->recipientForm->getId())->getSubject()."\""
            )
        )
    )?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Core::BUNDLE)?>


    <form id="<?=get_class($this->recipientForm)?>" action="newsletter/send" method="post">

        <div>
            <input type="hidden"
                   name="id"
                   value="<?=$this->recipientForm->getId()?>" />
            <input type="hidden"
                   name="<?=MVC::TOKEN_KEY?>"
                   value="<?=$this->request->getSession()->getAttribute(MVC::TRANSACTION_TOKEN_KEY)?>" />
        </div>

        <fieldset>

            <legend><?=$this->message("label.receive", _Newsletter::BUNDLE)?></legend>

            <? $recipients = $this->recipients($this->recipientForm->getId(), "NOT IN"); ?>

            <? if(count($recipients) > 0): ?>
            <table cellspacing="0" cellpadding="0" class="settings">
            <tr>
                <th colspan="3">
                    <a href="javascript:checkAll('<?=get_class($this->recipientForm)?>', 'recipients')"><?=$this->message("choose.check-all", _Core::BUNDLE)?></a>
                    /
                    <a href="javascript:uncheckAll('<?=get_class($this->recipientForm)?>', 'recipients')"><?=$this->message("choose.uncheck-all", _Core::BUNDLE)?></a>
                </th>
            </tr>
            <?
            $count = 0;
            for($j=0; $j<count($recipients); $j++): ?>

                <tr class="ctrl<?=$this->error("recipients")?>">

                    <th class="narrow">
                        <input name="recipients[]"
                               value="<?=$recipients[$j]->getStaffId()?>"
                               id="recipient_<?=$recipients[$j]->getStaffId()?>"
                               type="checkbox"
                               class="check"
                               <?=in_array($recipients[$j]->getStaffId(), $this->recipientForm->getRecipients()) ? " checked=\"checked\"" : ""?> />
                    </th>
                    <th class="flag">
                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($recipients[$j]->getLanguageCode()).".png")?>"
                             width="16" height="11" alt="<?=$recipients[$j]->getLanguage()->getName()?>"
                             title="<?=$recipients[$j]->getLanguage()->getName()?>" />
                    </th>
                    <th><label for="recipient_<?=$recipients[$j]->getStaffId()?>"><?=$recipients[$j]->getFirstname()?> <?=$recipients[$j]->getSurname()?></label></th>

                </tr>

            <? endfor; ?>
            </table>
            <? endif; ?>

        </fieldset>

        <fieldset>

            <legend><?=$this->message("label.received", _Newsletter::BUNDLE)?></legend>

            <? $recipients = $this->recipients($this->recipientForm->getId(), "IN"); ?>

            <? if(count($recipients) > 0): ?>
            <table cellspacing="0" cellpadding="0" class="settings">
            <tr>
                <th colspan="3">
                    <a href="javascript:checkAll('<?=get_class($this->recipientForm)?>', 'received')">
                        <?=$this->message("choose.check-all", _Core::BUNDLE)?>
                    </a> /
                    <a href="javascript:uncheckAll('<?=get_class($this->recipientForm)?>', 'received')">
                        <?=$this->message("choose.uncheck-all", _Core::BUNDLE)?>
                    </a>
                </th>
            </tr>
            <?
            $count = 0;
            for($j=0; $j<count($recipients); $j++): ?>

                <tr class="ctrl<?=$this->error("received")?>">
                    <th class="narrow">
                        <input name="received[]"
                               value="<?=$recipients[$j]->getStaffId()?>"
                               id="received_<?=$recipients[$j]->getStaffId()?>"
                               type="checkbox"
                               class="check" />
                    </th>
                    <th class="flag">
                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($recipients[$j]->getLanguageCode()).".png")?>"
                             width="16" height="11" alt="<?=$recipients[$j]->getLanguage()->getName()?>"
                             title="<?=$recipients[$j]->getLanguage()->getName()?>" />
                    </th>
                    <th><label for="received_<?=$recipients[$j]->getStaffId()?>"><?=$recipients[$j]->getFirstname()?> <?=$recipients[$j]->getSurname()?></label></th>
                </tr>

            <? endfor; ?>
            </table>
            <? endif; ?>

        </fieldset>

        <div class="buttons" style="padding-left:20px">

            <input type="button"
                   onclick="to('newsletter/list')"
                   value="<?=$this->message("button.cancel", _Core::BUNDLE)?>"
                   class="button" />
            <input type="submit"
                   value="Send"
                   class="button" />

        </div>

    </form>

<?=$this->footer()?>